package com.kfm.base.io.xml;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;

import java.net.URLEncoder;

public class Demo05 {

    public static void main(String[] args) {
        String url = "https://www.yeyulingfeng.com/tools/music/";

        String name = "好运来";
        String enName = URLEncoder.encode(name);

        String body = "input=" + enName + "&filter=name&type=netease&page=1";
        HttpRequest referer = HttpRequest.post(url)
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36")
                .header("x-requested-with", "XMLHttpRequest")
//                .header("Referer", "https://www.yeyulingfeng.com/tools/music/?name=" + enName + "&type=netease")
//                .header("accept", "application/json, text/javascript, */*; q=0.01")
//                .header("origin", "https://www.yeyulingfeng.com")
//                .header("Sec-Ch-Ua", "\"Chromium\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Google Chrome\";v=\"116\"")
//                .header("sec-ch-ua-mobile", "?0")
//                .header("sec-ch-ua-platform", "\"Windows\"")
//                .header("cache-control", "no-cache")
//                .header("sec-fetch-dest", "empty")
//                .header("cache-control", "no-cache")
//                .header("sec-fetch-mode", "cors")
//                .header("referrerPolicy", "strict-origin-when-cross-origin")
//                .header("mode", "cors")
//                .header("credentials", "omit")
                .contentType("application/x-www-form-urlencoded; charset=UTF-8")
                .body(body);
        referer.header("Content-Length", String.valueOf(body.length()));

        HttpResponse response = referer.execute();

        JSONObject jsonObject = JSONObject.parseObject(response.body());
        Object o = jsonObject.getJSONArray("data").getJSONObject(0).get("url");
        System.out.println(o);


    }
}
